package org.javaboy.properties;

import com.github.houbb.property.bs.PropertyBs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * test controller
 * @author WangGang
 * @date 2021/10/28
 */
@RestController
public class HelloController {
    @Autowired
    private Book book;
    @Autowired
    private Config config;

    /**
     * 
     * hello
     * @author WangGang
     * @date 2021/10/28
     */
    @GetMapping("/hello")
    public String hello() {
        System.out.println(book);
        return "hello";
    }

    /**
     * 
     * get book info
     * @author WangGang
     * @date 2021/10/28
     */
    @GetMapping("book")
    public String getBook() {
        String name=book.getName();
        String str=PropertyBs.getInstance("read.properties").get("hello");
        final String value = PropertyBs.getInstance("read.properties")
                .getOrDefault("hello2", "default");
//        setBean();
        readBean();
        return book.toString();
    }

    /**
     * 
     * get config info
     * @author WangGang
     * @date 2021/10/28
     */
    @GetMapping("config")
    public String getConfig() {
        String studentName= config.getStudentName();
        return config.toString();
    }

    private void setBean(){
        User user = new User();
        user.setName("hello");
        user.setHobby("hobby222");

//        final long time = 1574147668411L;
//        user.setBirthday(new Date(time));

        PropertyBs propertyBs = PropertyBs.getInstance("setBean.properties")
                .set(user);
        String bobby=propertyBs.get("hobby");

    }

    private void readBean(){
        PropertyBs propertyBs = PropertyBs.getInstance("setBean.properties");
        User user = new User();
        propertyBs.asBean(user);
        String str= user.getHobby();
    }

}
